package com.zhang.wanandroid.ui.pages

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import com.module.compose.base.ComposeActivity
import com.module.compose.base.composable.CommonPage
import com.study.messagebus.Register
import com.zrouter.annotation.Route

@Register
@Route("wanAndroid/LoginActivity")
class LoginActivity : ComposeActivity<LoginModel>() {

    @Composable
    override fun ContentView() {
        var userName by remember { mutableStateOf("") }
        var password by remember { mutableStateOf("") }

        CommonPage(
            title = "登录",
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Top
        ) {
            OutlinedTextField(
                value = userName,
                onValueChange = {
                    userName = it
                },
                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(10.dp, 180.dp, 10.dp, 10.dp),
                label = {
                    Text(text = "用户名")
                },
            )
            OutlinedTextField(
                value = password,
                onValueChange = {
                    password = it
                },
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(10.dp),
                label = {
                    Text(text = "密码")
                },
                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
                visualTransformation = PasswordVisualTransformation(),
            )
            Spacer(modifier = Modifier.height(height = 20.dp))

            Button(onClick = { viewModel.login(userName, password) }) {
                Text("登录")
            }
        }
    }
}
